package com.tanhua.server.controller;

import com.tanhua.model.vo.ReportVo;
import com.tanhua.model.vo.SoulVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Create by: wanglei
 * @Date: 2021/11/7 12:40
 */

/**
 * 灵魂测试
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    //查看试卷列表
    @GetMapping
    public ResponseEntity showSouls() {
        List<SoulVo> soulVos = testSoulService.showSouls();
        return ResponseEntity.ok(soulVos);
    }

    //提交问卷
    @PostMapping
    public ResponseEntity submit(@RequestBody Map<String, List<Map<String, String>>> answers) {
        String reportId = testSoulService.submit(answers);
        return ResponseEntity.ok(reportId);
    }

    //查看测灵魂的结果
    @GetMapping("/report/{id}")
    public ResponseEntity showReport(@PathVariable("id")String id){
        Integer reporetId = null;
        if (!StringUtils.isEmpty(id)){
            reporetId = Integer.valueOf(id);
        }else{
            reporetId = 1;
        }
        ReportVo reportVo = testSoulService.showReport(reporetId);
        return ResponseEntity.ok(reportVo);
    }
}
